package com.haiqi.modules.map.service;

import com.haiqi.common.persistence.dao.ServerPointMapper;
import com.haiqi.common.persistence.dao.ShipInfoMapper;
import com.haiqi.common.persistence.dao.ShipServerMapper;
import com.haiqi.common.persistence.entity.ShipServer;
import com.haiqi.common.utils.DateUtils;
import com.haiqi.common.utils.UUIDGenerator;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * Created by liuxiayan on 2017/4/20.
 */
@Service
public class ShipServerService {
    @Autowired
    private ShipServerMapper shipServerMapper;

     @Autowired
     private ServerPointMapper serverPointMapper;

    @Autowired
    private ShipInfoMapper shipInfoMapper;


    public boolean saveserver(ShipServer shipServer)
    {
        if(StringUtils.isNotEmpty(shipServer.getSsid())){
            shipServer.setPublishtime(DateUtils.dateToString(new Date(), DateUtils.DATETIME_FORMAT));
            return shipServerMapper.updateByPrimaryKeySelective(shipServer);
        }else {
            shipServer.setSsid(UUIDGenerator.getUUID());
            shipServer.setPublishtime(DateUtils.dateToString(new Date(), DateUtils.DATETIME_FORMAT));
            return shipServerMapper.insert(shipServer);
        }
    }



    public List<ShipServer> getShipServerList(ShipServer shipServer){
        List<ShipServer> shipServers = shipServerMapper.selectShipServer(shipServer);
        return shipServers;
    }

    public ShipServer   getById(String ssid){
        ShipServer shipServer=shipServerMapper.selectByPrimaryKey(ssid);
        return shipServer;
    }

    public List<ShipServer> selectShipServer(ShipServer shipServer){
        List<ShipServer> shipServers = shipServerMapper.selectShipServer(shipServer);
        return shipServers;
    }

    public boolean delete(ShipServer shipServer){
        boolean success = false;
        int i = shipServerMapper.deleteByPrimaryKey(shipServer.getSsid());
        if(i > 0){
            success = true;
        }
        return success;
    }

    public boolean dropServer(String ssid) {
        return shipServerMapper.dropServer(ssid);
    }


}
